package com.bookmanager.www.common.utils;

import com.bookmanager.www.common.Constants.PreferentialConstant;

import java.math.BigDecimal;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: 风离
 * @Date: 2021/10/29/17:44
 * @Description: 计算优惠和等级工具类
 */
public class OffersAndRatingsUtils {

    /**
     * 根据用户等级获取折扣等级
     */
    public static double getTheDiscount(int level)
    {
        if(level==0)
        {
            return PreferentialConstant.discount0;
        }else if(level==1)
        {
            return PreferentialConstant.discount1;
        }else if(level==2)
        {
            return PreferentialConstant.discount2;
        }else if(level==3)
        {
            return PreferentialConstant.discount3;
        }else if(level==4)
        {
            return PreferentialConstant.discount4;
        }else if(level==5)
        {
            return PreferentialConstant.discount5;
        }else if(level==6)
        {
            return PreferentialConstant.discount6;
        }else if(level==7)
        {
            return PreferentialConstant.discount7;
        }else if(level==8)
        {
            return PreferentialConstant.discount8;
        }else {
            return 0;
        }
    }


    /**
     * 根据消费金额判断用户等级
     */
    public static int judgeTheLevel(BigDecimal cumulativeConsumption)
    {
        if(cumulativeConsumption.compareTo(new BigDecimal(PreferentialConstant.SuperMember8))>0)
        {
            return 8;
        }else if(cumulativeConsumption.compareTo(new BigDecimal(PreferentialConstant.SuperMember7))>0)
        {
            return 7;
        }else if(cumulativeConsumption.compareTo(new BigDecimal(PreferentialConstant.SuperMember6))>0)
        {
            return 6;
        }else if(cumulativeConsumption.compareTo(new BigDecimal(PreferentialConstant.SuperMember5))>0)
        {
            return 5;
        }else if(cumulativeConsumption.compareTo(new BigDecimal(PreferentialConstant.SuperMember4))>0)
        {
            return 4;
        }else if(cumulativeConsumption.compareTo(new BigDecimal(PreferentialConstant.SuperMember3))>0)
        {
            return 3;
        }else if(cumulativeConsumption.compareTo(new BigDecimal(PreferentialConstant.SuperMember2))>0)
        {
            return 2;
        }else if(cumulativeConsumption.compareTo(new BigDecimal(PreferentialConstant.SuperMember1))>0)
        {
            return 1;
        }
        return 0;
    }

}
